package com.ming.attendance.mapper;

import com.ming.attendance.po.AttendanceEvent;
import com.ming.attendance.po.EventUser;
import org.apache.ibatis.annotations.*;

import java.awt.*;
import java.util.List;

@Mapper
public interface EventUserMapper {
    // 创建事件用户关系    参数：eventid、openid、joinTime
    @Insert("INSERT INTO `event_user`(`eventid`,`openid`,`join_time`,`identity`) VALUES (#{eventid},#{openid},#{joinTime},#{identity});")
    int CreateEventUser(EventUser eventUser);

    // 根据eventid,找到EventUser列表
    // @Select("SELECT * FROM `event_user` WHERE eventid = #{eventid}")
    List<EventUser> getEventUserByEventid(String eventid);

    // 标记该打卡事件该用户已打卡   参数：eventid、openid
    @Update("UPDATE `event_user` SET `isChecked`=1,`check_time`=#{checkTime} " +
            "WHERE eventid=#{eventid} AND openid=#{openid};")
    int signUp(String eventid, String openid, String checkTime);

    // 判断用户是否已打卡
    @Select("SELECT isChecked\n" +
            "FROM `event_user`\n" +
            "WHERE eventid=#{eventid} AND openid=#{openid};")
    int isChecked(String eventid,String openid);

    @Select("SELECT * FROM event_user\n" +
            "WHERE eventid = #{eventid} AND openid = #{openid}")
    EventUser getEventUser(String eventid,String openid);

    // 根据openid,找到EventUser列表  普通查找
    @Select("SELECT * FROM `event_user` WHERE openid = #{openid}")
    List<EventUser> getEventUserByOpenid(String openid);

    // 删除关系
    @Delete("DELETE FROM `event_user` WHERE eventid = #{eventid}")
    int deleteEventUser(EventUser eventUser);
}
